import 'package:flutter/material.dart';
import 'package:net/core/hi_base_tab_state.dart';
import 'package:net/http/dao/notice_dao.dart';
import 'package:net/model/notice_mo.dart';

import 'notice_card.dart';

class NoticePage extends StatefulWidget {
  NoticePage({Key key}) : super(key: key);

  @override
  _NoticePageState createState() => _NoticePageState();
}

class _NoticePageState
    extends HBaseTabState<NoticeMo, NoticeItemMo, NoticePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Column(
      children: [_buildNavigationBar(), Expanded(child: super.build(context))],
    ));
  }

  _buildNavigationBar() {
    return AppBar(title: Text('通知'), centerTitle: true);
  }

  @override
  get contentChild => ListView.builder(
        padding: EdgeInsets.only(top: 10),
        physics: const AlwaysScrollableScrollPhysics(),
        itemCount: dataList.length,
        controller: scrollController,
        itemBuilder: (context, index) =>
            NoticeCard(noticeItemMo: dataList[index]),
      );

  @override
  Future<NoticeMo> getData(int pageIndex) async {
    NoticeMo result = await NoticeDao.get(pageIndex: pageIndex, pageSize: 10);
    return result;
  }

  @override
  List<NoticeItemMo> parseList(NoticeMo resulet) {
    return resulet.list;
  }

  @override
  bool get wantKeepAlive => true;
}
